package com.xxx.yuedong.mine.controller;

import com.xxx.yuedong.common.ProjectUtils;
import com.xxx.yuedong.common.R;
import com.xxx.yuedong.community.pojo.Dynamic;
import com.xxx.yuedong.mine.controller.form.UpdatePhoneForm;
import com.xxx.yuedong.mine.pojo.Address;
import com.xxx.yuedong.mine.pojo.District;
import com.xxx.yuedong.mine.pojo.User;
import com.xxx.yuedong.mine.pojo.vo.*;
import com.xxx.yuedong.mine.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 *
 * @Author Lry
 * @Date 2023-08-02
 */


@Api(tags = "我的模块")
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CommonService commonService;


    @GetMapping("/queryUserInfo")
    @ApiOperation(value = "查询用户信息")
    public R queryUserInfo(){
        UserVO userVO =commonService.queryUserInfo(ProjectUtils.getUserId());
        return R.ok().put("data",userVO);
    }

    @ApiImplicitParam(name = "userId",value = "用户id",required = true)
    @GetMapping("/queryUserInfoByUserId")
    @ApiOperation(value = "查询用户id用户信息")
    public R queryUserInfoByUserId(Long userId){
        UserVO userVO =commonService.queryUserInfo(userId);
        return R.ok().put("data",userVO);
    }


    @PostMapping("/updateUserInfo")
    @ApiOperation(value = "修改用户信息")
    public R updateUserInfo(@RequestBody User user){
        user.setId(ProjectUtils.getUserId());
        commonService.updateUserInfo(user);
        return R.ok();
    }


    @GetMapping("/queryDynamicList")
    @ApiOperation(value = "查询动态列表")
    public R queryDynamicList(){
        List<Dynamic> dynamics=commonService.queryDynamicList(ProjectUtils.getUserId());
        return R.ok().put("data",dynamics);
    }



    @GetMapping("/queryFollowList")
    @ApiOperation(value = "查询关注列表")
    public R queryFollowList(){
        List<FollowVO> dynamics=commonService.queryFollowList(ProjectUtils.getUserId());
        return R.ok().put("data",dynamics);
    }


    @GetMapping("/queryFansList")
    @ApiOperation(value = "查询粉丝列表")
    public R queryFansList(){
        List<FansVO> fansVOS=commonService.queryFansList(ProjectUtils.getUserId());
        return R.ok().put("data",fansVOS);
    }

    @ApiImplicitParam(name = "toId",value = "用户id",required = true)
    @GetMapping("/followUser")
    @ApiOperation(value = "关注用户")
    public R followUser(Long toId){
        commonService.followUser(ProjectUtils.getUserId(),toId);
        return R.ok();
    }

    @GetMapping("/querySportsCareerData")
    @ApiOperation(value = "运动生涯数据查询")
    public R querySportsCareerData(){
        RunVO runVO=commonService.querySportsCareerData(ProjectUtils.getUserId());
        return R.ok().put("data",runVO);
    }


    @ApiImplicitParam(name = "date",value = "日期，格式：2021-02-02",required = true)
    @GetMapping("/queryMyPlan")
    @ApiOperation(value = "运动生涯数据查询")
    public R queryMyPlan(String date){
        List<PlanVO> planVOS=commonService.queryMyPlan(ProjectUtils.getUserId(),date);
        return R.ok().put("data",planVOS);
    }


    @GetMapping("/queryMyCourseTags")
    @ApiOperation(value = "查询我收藏的课程标签")
    public R queryMyCourseTags(){
        Set<String> tags=commonService.queryMyCourseTags(ProjectUtils.getUserId());
        return R.ok().put("data",tags);
    }


    @ApiImplicitParam(name = "tag",value = "标签名称",required = true)
    @GetMapping("/queryMyCollect")
    @ApiOperation(value = "查询我的收藏课程")
    public R queryMyCollect(String tag){
        List<CollectVO> collectVOS=commonService.queryMyCollect(ProjectUtils.getUserId(),tag);
        return R.ok().put("data",collectVOS);
    }

   @GetMapping("/collectCourse")
   @ApiOperation(value = "收藏课程")
   public R collectCourse(Long courseId){
       commonService.collectCourse(ProjectUtils.getUserId(),courseId);
       return R.ok();
   }

   @ApiImplicitParam(name = "courseId",value = "课程id",required = true)
   @GetMapping("/queryCourseDetail")
   @ApiOperation(value = "课程详情")
   public R queryCourseDetail(Long courseId){
       CourseVO courseVO=commonService.queryCourseDetail(ProjectUtils.getUserId(),courseId);
       return R.ok().put("data",courseVO);
   }


   @GetMapping("/queryOrderList")
   @ApiOperation(value = "查询订单列表")
   public R queryOrderList(){
       List<OrderVO> list=commonService.queryOrderList(ProjectUtils.getUserId());
       return R.ok().put("data",list);
   }


    @PostMapping("/updatePhone")
    @ApiOperation(value = "修改手机号")
    public R updatePhone(@RequestBody UpdatePhoneForm phoneForm){
        phoneForm.setUserId(ProjectUtils.getUserId());
        commonService.updatePhone(phoneForm);
        return R.ok();
    }


    @PostMapping("/queryUserLikeDynamicNum")
    @ApiOperation(value = "查询用户喜欢的动态数量")
    public R queryUserLikeDynamicNum(){
        Integer num=commonService.queryUserLikeDynamicNum(ProjectUtils.getUserId());
        return R.ok().put("likeDynamicNum",num);
    }

    @PostMapping("/queryUserLikeDynamicList")
    @ApiOperation(value = "查询用户喜欢的动态列表")
    public R queryUserLikeDynamicList(){
        List<Dynamic> list=commonService.queryUserLikeDynamicList(ProjectUtils.getUserId());
        return R.ok().put("likeDynamicList",list);
    }


    @PostMapping("/queryUserPoints")
    @ApiOperation(value = "查询用户积分")
    public R queryUserPoints(){
        UserVO userVO =commonService.queryUserInfo(ProjectUtils.getUserId());
        return R.ok().put("points",userVO.getPoints());
    }


    @GetMapping("/queryMyAddress")
    @ApiOperation(value = "查询自己的收货地址")
    public R queryMyAddress(){
        List<AddressVO> list=commonService.queryMyAddress(ProjectUtils.getUserId());
        return R.ok().put("data",list);
    }

    @PostMapping("/saveAddress")
    @ApiOperation(value = "添加地址信息")
    public R saveAddress(@RequestBody Address address){
        address.setUserId(ProjectUtils.getUserId());
        commonService.saveAddress(address);
        return R.ok();
    }


    @PostMapping("/updateAddress")
    @ApiOperation(value = "修改地址信息")
    public R updateAddress(@RequestBody Address address){
        address.setUserId(ProjectUtils.getUserId());
        commonService.updateAddress(address);
        return R.ok();
    }

    @GetMapping("/deleteAddress")
    @ApiOperation(value = "删除地址信息")
    public R deleteAddress(Long id){
        commonService.deleteAddress(id);
        return R.ok();
    }




}
